<template>
    <div>
        <h3>康复理疗信息</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">项目名称</td>
                    <td><input type="text" v-model="info.Pname"></td>
                </tr>
                <tr>
                    <td align="right">项目编码</td>
                    <td>
                        <input type="text" v-model="info.CarID">
                    </td>
                </tr>
                <tr>
                    <td align="right">佣金（元）</td>
                    <td><input type="text" v-model="info.Price"></td>
                </tr>
                <tr>
                    <td align="right">服务人数</td>
                    <td>
                        <input type="text" v-model="info.Num">
                    </td>
                </tr>
                <tr>
                    <td align="right">服务时长</td>
                    <td><input type="text" v-model="info.TimeNum"></td>
                </tr>
                <tr>
                    <td align="right">项目说明</td>
                    <td><textarea rows="5" cols="25" v-model="info.Detail"></textarea></td>
                </tr>
                <tr>
                    <td align="right">状态</td>
                    <td>
                        <input type="radio" name="state" v-model="info.State" value="true">启用
                        <input type="radio" name="state" v-model="info.State" value="false">禁用
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="确认" class="btn btn-success" @click="add"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { ref, reactive, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
const route = useRoute();
const routr = useRouter();

//添加
let info: any = reactive({
    "Pname": "",
    "CarID": moment(new Date()).format("yyyyMMdd")+Math.random().toString().substring(2,5),
    "Price": "",
    "Num": "",
    "TimeNum": "",
    "Detail": "",
    "State": true,
})
const add = () => {
    if (info.Pname == "") {
        alert("项目名称不能为空");
        return;
    }
    if (info.Price == "") {
        alert("佣金不能为空");
        return;
    }
    if (info.Num == "") {
        alert("服务人数不能为空");
        return;
    }
    if(isNaN(info.Num)){
        alert("服务人数只能是整数");
        return;
    }
    if (info.TimeNum == "") {
        alert("服务时长不能为空");
        return;
    }
    if(isNaN(info.TimeNum)){
        alert("服务时长只能是整数");
        return;
    }
    axios({
        url: "/api/Food/AddPTS",
        method: "post",
        data: info
    })
        .then(res => {
            if (res.data == -1) {
                alert("项目名称重复");
                return;
            } else if (res.data > 0) {
                alert("添加成功");
                routr.push("/ptsList")
            } else {
                alert("添加失败");
                return;
            }
        })
        .catch(err => {
            console.log(err);
        })
}


</script>

<style scoped></style>